package cntv.player.media.player;

import java.io.IOException;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.view.Surface;
import android.view.SurfaceHolder;

public interface IMediaPlayer {
    /*
     * Do not change these values without updating their counterparts in native
     */
    public static final int MEDIA_INFO_UNKNOWN = 1;
    public static final int MEDIA_INFO_STARTED_AS_NEXT = 2;
    public static final int MEDIA_INFO_VIDEO_RENDERING_START = 3;
    public static final int MEDIA_INFO_VIDEO_TRACK_LAGGING = 700;
    public static final int MEDIA_INFO_BUFFERING_START = 701;
    public static final int MEDIA_INFO_BUFFERING_END = 702;
    public static final int MEDIA_INFO_BAD_INTERLEAVING = 800;
    public static final int MEDIA_INFO_NOT_SEEKABLE = 801;
    public static final int MEDIA_INFO_METADATA_UPDATE = 802;
    public static final int MEDIA_INFO_TIMED_TEXT_ERROR = 900;

    public static final int MEDIA_ERROR_UNKNOWN = 1;
    public static final int MEDIA_ERROR_SERVER_DIED = 100;
    public static final int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200;
    public static final int MEDIA_ERROR_IO = -1004;
    public static final int MEDIA_ERROR_MALFORMED = -1007;
    public static final int MEDIA_ERROR_UNSUPPORTED = -1010;
    public static final int MEDIA_ERROR_TIMED_OUT = -110;
    
    public static final int MEDIA_PLAYER_KOO = 300;
    public static final int MEDIA_PLAYER_SYSTEM = 301;
    public static final int MEDIA_PLAYER_VITAMIO = 302;
    public static int MEDIA_PLAYER_DEFAULT = MEDIA_PLAYER_KOO;
    
    
	public static final int SLIDE_STATE_NONE = 400;
	public static final int SLIDE_STATE_RIGHT = 401;
    public static final int SLIDE_STATE_LEFT = 402;
    public static final int SLIDE_STATE_UP = 403;
    public static final int SLIDE_STATE_DOWN = 404;
    
    public static final int SLIDE_STATE_HORIZONRAL = 405;
    public static final int SLIDE_STATE_VERTICAL = 406;
    
    
    
    

    public abstract void setDisplay(SurfaceHolder sh);

    public abstract void setDataSource(String path) throws IOException,
            IllegalArgumentException, SecurityException, IllegalStateException;

    public abstract String getDataSource();

    public abstract void prepareAsync() throws IllegalStateException;

    public abstract void start() throws IllegalStateException;

    public abstract void stop() throws IllegalStateException;

    public abstract void pause() throws IllegalStateException;

    public abstract void setScreenOnWhilePlaying(boolean screenOn);

    public abstract int getVideoWidth();

    public abstract int getVideoHeight();
    
    public abstract float getVideoAspectRatio();

    public abstract boolean isPlaying();

    public abstract void seekTo(long msec) throws IllegalStateException;

    public abstract long getCurrentPosition();

    public abstract long getDuration();

    public abstract void release();

    public abstract void reset();

    public abstract MediaInfo getMediaInfo();

    public abstract void setLogEnabled(boolean enable);

    public abstract boolean isPlayable();

    public abstract void setOnPreparedListener(OnPreparedListener listener);

    public abstract void setOnCompletionListener(OnCompletionListener listener);

    public abstract void setOnBufferingUpdateListener(
            OnBufferingUpdateListener listener);

    public abstract void setOnSeekCompleteListener(
            OnSeekCompleteListener listener);

    public abstract void setOnVideoSizeChangedListener(
            OnVideoSizeChangedListener listener);

    public abstract void setOnErrorListener(OnErrorListener listener);

    public abstract void setOnInfoListener(OnInfoListener listener);

    /*--------------------
     * Listeners
     */
    public static interface OnPreparedListener {
        void onPrepared(IMediaPlayer mp);
    }

    public static interface OnCompletionListener {
        void onCompletion(IMediaPlayer mp);
    }

    public static interface OnBufferingUpdateListener {
        void onBufferingUpdate(IMediaPlayer mp, int percent);
    }

    public static interface OnSeekCompleteListener {
        public void onSeekComplete(IMediaPlayer mp);
    }

    public static interface OnVideoSizeChangedListener {
        public void onVideoSizeChanged(IMediaPlayer mp, int width, int height,
                int sar_num, int sar_den);
    }

    public static interface OnErrorListener {
        boolean onError(IMediaPlayer mp, int what, int extra);
    }

    public static interface OnInfoListener {
        boolean onInfo(IMediaPlayer mp, int what, int extra);
    }
    
	/**
	 * videoview surfaceview的创建与销毁
	 * @author zengliang
	 *
	 */
	public static interface OnSurfaceListener{
		void onSurfaceCreate();
		void onSurfaceDestroyed();
	}
	/**
	 * videoview的滑动事件
	 * @author zengliang
	 *
	 */
	public static interface OnSlideListener{
		void onSlideStart(int direction);
		void onSliding(int direction, int distance);
		void onSlideEnd(int direction, int distance);
	}
	
	public static interface OnTimedTextListener {
		/**
		 * Called to indicate that a text timed text need to display
		 * 
		 * @param text
		 *            the timedText to display
		 */
		public void onTimedText(String text);

		/**
		 * Called to indicate that an image timed text need to display
		 * 
		 * @param pixels
		 *            the pixels of the timed text image
		 * @param width
		 *            the width of the timed text image
		 * @param height
		 *            the height of the timed text image
		 */
		public void onTimedTextUpdate(byte[] pixels, int width, int height);
	}
	/**
	 * 当MediaController为空时,点击视频画面时监听
	 * @author zengliang
	 *
	 */
	public static interface OnVideoClickListener {
		void onVideoClick();
	}
	
    /*--------------------
     * Optional
     */
    public abstract void setAudioStreamType(int streamtype);

    public abstract void setKeepInBackground(boolean keepInBackground);

    public abstract int getVideoSarNum();

    public abstract int getVideoSarDen();

    @Deprecated
    public abstract void setWakeMode(Context context, int mode);

    @TargetApi(Build.VERSION_CODES.BASE)
    public abstract void setSurface(Surface surface);
}
